package view.stage
{
	import data.MapData;
	
	import flash.display.Sprite;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	public class StageBase extends Sprite
	{
		private var refreshTimer :Timer;
		private var _refreshInterval :int = 0;
		/**
		 * 可视范围宽 
		 */		
		public var visibleWidth :Number;
		/**
		 * 可视范围高 
		 */		
		public var visibleHeight :Number;
		/**
		 * 地图信息 
		 */		
		public var mapData :MapData;
		public function StageBase()
		{
			super();
			addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
			addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
			addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
			addEventListener(MouseEvent.CLICK,clickHandler);
		}
		
		private function addedToStageHandler(evnet :Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
			initGame();
		}
		
		public function get refreshInterval():int
		{
			return _refreshInterval;
		}
		
		/**
		 * 自動刷新间隔，默认为不刷新 
		 * @param value
		 * 
		 */		
		public function set refreshInterval(value:int):void
		{
			if(value == _refreshInterval) return;
			_refreshInterval = value;
			
			if(value == 0)
			{
				if(refreshTimer)
				{
					refreshTimer.removeEventListener(TimerEvent.TIMER,refreshHandler);
					refreshTimer.stop();
					refreshTimer = null;
				}
			}else
			{
				if(!refreshTimer)
				{
					refreshTimer = new Timer(value,int.MAX_VALUE);
					refreshTimer.addEventListener(TimerEvent.TIMER,refreshHandler);
					refreshTimer.start();
				}
			}
			
		}
		/**
		 * 更新函数 
		 * @param event
		 * 
		 */		
		public function refreshHandler(event :TimerEvent):void
		{
			
		}
		/**
		 * 初始化游戏 
		 * 
		 */		
		public function initGame():void
		{
//			full();
			stage.addEventListener(Event.RESIZE,resizeHandler);
		}
		
		/**
		 * 全屏切换 
		 */		
		public function full(o:Object = null):void
		{
			var v:Boolean;
			if(o == null)
			{
				v = stage.displayState != StageDisplayState.FULL_SCREEN;
			}
			else
			{ 
				v = o as Boolean;
			}
			
			if(v)
			{
				stage.displayState = StageDisplayState.FULL_SCREEN;
			}
			else
			{
				stage.displayState = StageDisplayState.NORMAL;
			}
		}
		
		/**
		 * 鼠标按下 
		 * @param event
		 * 
		 */		
		public function mouseDownHandler(event :MouseEvent):void
		{
		}
		/**
		 * 鼠标弹起 
		 * @param event
		 * 
		 */		
		public function mouseUpHandler(event :MouseEvent):void
		{
		}
		/**
		 * 鼠标点击 
		 * @param event
		 * 
		 */		
		public function clickHandler(event :MouseEvent):void
		{
			
		}
		/**
		 *  调整大小
		 * @param event
		 * 
		 */		
		public function resizeHandler(event :Event):void
		{
			
		}
	}
}